import matplotlib.pyplot as plt
import seaborn as sns
import plotly.express as px

class Visualizer:
    def plot_trend(self, df, time_col, index_col):
        """时间趋势图"""
        plt.figure(figsize=(12, 6))
        sns.lineplot(data=df, x=time_col, y=index_col, marker='o')
        plt.title("绿色生产力指数趋势")
        plt.xlabel("时间")
        plt.ylabel("指数")
        plt.grid(True)
        plt.show()

    def plot_heatmap(self, df, cols):
        """相关性热力图"""
        plt.figure(figsize=(10, 8))
        corr = df[cols].corr()
        sns.heatmap(corr, annot=True, cmap='coolwarm')
        plt.title("指标相关性分析")
        plt.show()

    def plot_interactive_map(self, df, location_col, index_col):
        """Plotly地理分布图"""
        fig = px.choropleth(
            df,
            locations=location_col,
            locationmode="country names",
            color=index_col,
            hover_name="Year",
            title="全球绿色生产力指数分布"
        )
        fig.show()